<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>毕业答辩</title>
    <link rel="stylesheet" type="text/css" href="../static/css/top.css"/>
    <link rel="stylesheet" type="text/css" href="../static/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="../static/css/footer.css"/>
    <link rel="stylesheet" type="text/css" href="../static/css/work.css"/>
</head>
<body>
<div id="top" class="layui-fluid layui-bg-black" style="height: 58px;">
    <div class="layui-row">
        <div class="layui-col-md2 layui-col-md-offset1">
            <img src="../static/img/logo-v3.png" style="width: 180px; height: 50px;">
        </div>
        <div class="layui-col-md4">
            <ul>
                <li><a href="#">首页</a></li>
                <li><a href="#">题库</a></li>
                <li><a href="#">面试</a></li>
                <li><a href="#">学习</a></li>
                <li><a href="#">求职</a></li>
                <li><a href="#">讨论区</a></li>
                <li><a href="#">发现</a></li>
            </ul>
        </div>
        <div class="layui-col-md2">
            <input type="text" name="search" id="search" placeholder="帖子、试题、试卷、公司、牛友"/>
            <a href="#"><i class="layui-icon layui-icon-search"></i></a>
        </div>
        <div class="layui-col-md3 ">
            <div class="z">
                <i class="layui-icon layui-icon-cellphone"></i>APP
                <span>|</span>
            </div>
            <div class="x">
                <i class="layui-icon layui-icon-template-1"></i>企业版
            </div>
            <div class="y">
                <a href="../front/login.html">登录/注册</a>
            </div>
        </div>
    </div>
</div>

<div class="topic_box">
    <div class="title">
        <div class="icon_help">
            <i class="layui-icon layui-icon-help"></i>
        </div>
        <p>[单选题]（每题20分）</p>
    </div>
    <form action="" method="" class="layui-form">
        <div class="question_box">


        </div>

        <div class="score">
            <div class="discribe">
                得分
            </div>
            <div class="grade">
                0
            </div>
        </div>
        <div class="submit">
            <form action="" class="layui-form">
                <input type="hidden" id="userName" name="userName">
                <input type="hidden" id="sum" name="sum">
                <button type="button" id="btn" onclick="clickBtn()" lay-submit lay-filter="topic_sub" class="layui-btn layui-btn-danger"
                        style="width: 100px;">查看分数
                </button>
            </form>
        </div>
    </form>
</div>


<!-- 尾部 -->
<div class="layui-fluid layui-bg-black">
    <div class="layui-row" style="height: 220px;">
        <div class="layui-col-md2 layui-col-md-offset2">
            <div id="ft_img">
                <img src="../static/img/app_download.png"
                     style="height: 110px; width: 110px;border: 8px solid dimgray;">
            </div>
            <div id="ft_font">
                <p>扫一扫，把题目装进口袋</p>
            </div>
        </div>
        <div id="ft_info" class="layui-col-md3" style="height: 220px;">
            <div id="web_name">
                牛客网，互联网必备求职神器
            </div>
            <div id="web_icon">
                <a href="#"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="#"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="#"><i class="layui-icon layui-icon-login-weibo"></i></a>
            </div>
        </div>
        <div class="layui-col-md5">
            <ul class="links">
                <li>
                    <a href="#">关于我们</a>
                </li>

                <li>
                    <a href="#">加入我们</a>
                </li>

                <li>
                    <a href="#">意见反馈</a>
                </li>

                <li>
                    <a href="#">企业服务</a>
                </li>

                <li>
                    <a href="#">联系我们</a>
                </li>

                <li>
                    <a href="#">免责声明</a>
                </li>
                <li>
                    <a href="#">友情链接</a>
                </li>
            </ul>
            <div id="main">
                <p>公司地址：北京市朝阳区大屯路东金泉时代广场3单元</p>
                <p>联系方式：010-60728802(电话) admin@nowcoder.com </p>
                <p>牛客科技©2019 All rights reserved</p>
                <p>京ICP备14055008号-4增值电信业务经营许可证</p>
                <p><img src="../static/img/ghs.png">京公网安备 11010502036488号</p>
            </div>
        </div>

    </div>
</div>

<script src="../static/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var result;
    var x = 0;
    //-------------------判断用户是否登录------------------------
    window.clickChoose = function (tid, answer) {
        // alert(tid)
        if (sessionStorage.getItem("userName") == null) {
            layer.confirm("还没登录请登录", function () {
                window.location.href = '../front/login.html';
            })
        } else {
            // console.log(tid)
            console.log(sessionStorage.getItem("userName"))

            $.get('/school_project/answer/selectAnswerByTid', {"tid": tid}, function (res) {
                console.info(res)
                console.info(res.result)
                if (res.result == answer) {
                    x += 20;
                }
            }, 'json');
        }
    }
    //-------------------判断用户是否登录结束------------------------

    $(function () {
        layui.use(['rate', 'form', 'layer'], function () {
            var rate = layui.rate;
            var form = layui.form;
            var layer = layui.layer;
            form.render('radio');
            form.on('submit(topic_sub)',function (data) {
                console.log(data.field.userName)
                console.log(data.field.sum)
                $.post('/school_project/score/updateScore',{"userName":data.field.userName,"sum":data.field.sum},function (res) {
                    layer.msg("答题结束");
                    $("#btn").removeClass()
                    $("#btn").attr('class','layui-btn layui-btn-disabled ');
                });
            })
        });
        //    -----------------------截取页面url传入参数--------------------------
        var url = window.location.search;
        if (url.indexOf("?") !== -1) {
            // result = url.substr(url.indexOf("=") + 1)
            var schoolId = url.substring(url.indexOf("=") + 1, url.indexOf("&"));
            var courseId = url.substr(url.lastIndexOf("=") + 1);
            console.log("schoolId" + schoolId)
            console.log("courseId" + courseId)
        }
        //    -----------------------截取页面url传入参数方法结束--------------------------
      // ------------------------用户登录前随机出题（通过SchoolId和CourseId 出题） ------------------------
      if (sessionStorage.getItem("userName")==null){
          $.ajax({
              type: "GET",
              url: "/school_project/topic/selectTopicBySchoolIdAndCourseId",
              dataType: "json",
              data: {"schoolId": schoolId, "courseId": courseId},
              async: false,
              success: function (res) {
                  console.info(res)
                  console.log("题目个数" + res.length)
                  for (var i = 0; i < res.length; i++) {
                      console.info(res[i].titem)
                      var tid = res[i].tid;
                      console.info(tid)
                      var str = '<div class="question">';
                      str += '<p>' + res[i].titem + ' </p> </div>';
                      $.ajax({
                          type: "GET",
                          url: "/school_project/choose/selectChooseByTid",
                          data: {"tid": tid},
                          async: false,
                          success: function (choose) {
                              console.log(tid + "选项")
                              console.log(choose)
                              // var answer=choose.answer
                              str += '<div class="choice" onclick="clickChoose(\'' + tid + '\',\'' + choose[0].answer + '\')">';
                              str += '<div class="layui-input-inline">';
                              str += '<input type="radio" name="' + tid + '" lay-filter="redio_click" value="' + choose[0].answer + '" title="' + choose[0].answer + '"/> </div> </div>';
                              str += '<div class="choice" onclick="clickChoose(\'' + tid + '\',\'' + choose[1].answer + '\')">'
                              str += '<div class="layui-input-inline">'
                              str += '<input type="radio"  name="' + tid + '" lay-filter="redio_click" value="' + choose[1].answer + '" title="' + choose[1].answer + '"/></div></div>'
                              str += '<div class="choice" onclick="clickChoose(\'' + tid + '\',\'' + choose[2].answer + '\')">'
                              str += '<div class="layui-input-inline">'
                              str += '<input type="radio"  name="' + tid + '" lay-filter="redio_click" value="' + choose[2].answer + '" title="' + choose[2].answer + '"/></div></div>'
                              str += '<div class="choice" onclick="clickChoose(\'' + tid + '\',\'' + choose[3].answer + '\')">'
                              str += '<div class="layui-input-inline">'
                              str += '<input type="radio"   name="' + tid + '" lay-filter="redio_click" value="' + choose[3].answer + '" title="' + choose[3].answer + '"/></div></div>'
                              str += '<div class="collect"><p><i class="layui-icon layui-icon-star"></i>收藏本题</p>'
                              str += '<p><i class="layui-icon layui-icon-location"></i>标记一下</p><p><i class="layui-icon layui-icon-praise"></i>赞一下</p></div> '
                          }
                      })
                      $('.question_box').append(str)
                  }

              }
          })
      } else {
          //用户登录后查出score表中平均分根据平均分算出题目难度，再根据diff schoolId courseId 出题
          $.ajax({
              type:"GET",
              url:"/school_project/score/selectByName",
              data:{"userName":sessionStorage.getItem("userName")},
              dataType:'json',
              async:false,
              success:function(score){
                  console.log(score)
                  var avg=parseInt(score.sum/score.count);
                  var diff=0;
                  switch (parseInt(avg/10)) {
                      case 10:
                      case 9:   diff=5;break;
                      case 8:   diff=4;break;
                      case 7:   diff=3;break;
                      case 6:   diff=2;break;
                      default:diff=1;break;
                  }
                  $.ajax({
                      type: "GET",
                      url: "/school_project/topic/selectTopicBySchoolIdAndCourseIdAndDiff",
                      dataType: "json",
                      data: {"schoolId": schoolId, "courseId": courseId,"diff":diff},
                      async: false,
                      success: function (res) {
                          console.log(res)
                          for (var i = 0; i < res.length; i++) {
                              console.info(res[i].titem)
                              var tid = res[i].tid;
                              console.info(tid)
                              var str = '<div class="question">';
                              str += '<p>' + res[i].titem + ' </p> </div>';
                              $.ajax({
                                  type: "GET",
                                  url: "/school_project/choose/selectChooseByTid",
                                  data: {"tid": tid},
                                  async: false,
                                  success: function (choose) {
                                      console.log(tid + "选项")
                                      console.log(choose)
                                      // var answer=choose.answer
                                      str += '<div class="choice" onclick="clickChoose(\'' + tid + '\',\'' + choose[0].answer + '\')">';
                                      str += '<div class="layui-input-inline">';
                                      str += '<input type="radio" name="' + tid + '" lay-filter="redio_click" value="' + choose[0].answer + '" title="' + choose[0].answer + '"/> </div> </div>';
                                      str += '<div class="choice" onclick="clickChoose(\'' + tid + '\',\'' + choose[1].answer + '\')">'
                                      str += '<div class="layui-input-inline">'
                                      str += '<input type="radio"  name="' + tid + '" lay-filter="redio_click" value="' + choose[1].answer + '" title="' + choose[1].answer + '"/></div></div>'
                                      str += '<div class="choice" onclick="clickChoose(\'' + tid + '\',\'' + choose[2].answer + '\')">'
                                      str += '<div class="layui-input-inline">'
                                      str += '<input type="radio"  name="' + tid + '" lay-filter="redio_click" value="' + choose[2].answer + '" title="' + choose[2].answer + '"/></div></div>'
                                      str += '<div class="choice" onclick="clickChoose(\'' + tid + '\',\'' + choose[3].answer + '\')">'
                                      str += '<div class="layui-input-inline">'
                                      str += '<input type="radio"   name="' + tid + '" lay-filter="redio_click" value="' + choose[3].answer + '" title="' + choose[3].answer + '"/></div></div>'
                                      str += '<div class="collect"><p><i class="layui-icon layui-icon-star"></i>收藏本题</p>'
                                      str += '<p><i class="layui-icon layui-icon-location"></i>标记一下</p><p><i class="layui-icon layui-icon-praise"></i>赞一下</p></div> '
                                  }
                              })
                              $('.question_box').append(str)
                          }
                      }
                  })
              }
          })
      }
    //    ---------------------------出题功能结束-------------------------------
    })

    function clickBtn(){
        $('.grade').show();
        $('.discribe').css('margin-left', '0px')
        $('.grade').attr("disabled", "disabled")
    }
    $('#btn').click(function () {
        $('.grade').show();
        $('.discribe').css('margin-left', '0px');
        $('.grade').attr("disabled", "disabled");
        $('#sum').val(x)
        $('.grade').text($('#sum').val());
        $('#userName').val(sessionStorage.getItem("userName"));
    })



</script>
</body>
</html>
